#include <algorithm>
#include <cstdio>
#include <cstring>

const int N = 100005;
int t, n, k, f[2][N];
int e_cnt, heads[N];

struct Edge {
  int v, nxt;
} e[N];

inline void add(int u, int v) {
  e[++e_cnt].v = v, e[e_cnt].nxt = heads[u], heads[u] = e_cnt;
}

void solve(int x) {
  // f[0][x] = 1;
  for (int i = heads[x], v; i; i = e[i].nxt) {
    solve(v = e[i].v);
    f[0][x] += f[1][v];
  }
  for (int i = heads[x], v; i; i = e[i].nxt) {
    v = e[i].v;
    f[1][x] = std::max(f[1][x], f[0][x] - f[1][v] + f[0][v] + 2);
  }
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#endif
#ifndef LOCAL
  freopen("tree.in", "r", stdin);
  freopen("tree.out", "w", stdout);
#endif
#endif

  scanf("%d", &t);
  while (t--) {
    memset(heads, 0, sizeof(heads));
    e_cnt = 0;
    memset(f, 0, sizeof(f));
    scanf("%d%d", &n, &k);
    for (int i = 2, tmp; i <= n; ++i) {
      scanf("%d", &tmp);
      add(tmp, i);
    }
    solve(1);
    int ans = std::max(f[1][1], f[0][1]);
    if (ans >= k)
      printf("%d\n", (k + 1) >> 1);
    else
      printf("%d\n", ((ans + 1) >> 1) + k - ans);
  }
  return 0;
}